using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.ComponentModel;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;


namespace Ajax.Logging
{
    [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
    [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
    public class ListenerCollection : CollectionBase, IEnumerable<BaseListener>
    {
        private ExceptionManager _owner;

        public BaseListener this[int index]
        {
            [DebuggerStepThrough()]
            get
            {
                return (BaseListener)InnerList[index];
            }
            [DebuggerStepThrough()]
            set
            {
                InnerList[index] = value;
            }
        }

        internal ListenerCollection(ExceptionManager owner)
        {
            _owner = owner;
        }

        [SuppressMessage("Microsoft.Globalization", "CA1303:DoNotPassLiteralsAsLocalizedParameters")]
        public int Add(BaseListener value)
        {
            if (value == null)
            {
                throw new ArgumentException("Listener cannot be null.");
            }

            value.SetOwner(_owner);
            return InnerList.Add(value);
        }

        public bool Contains(BaseListener value)
        {
            return InnerList.Contains(value);
        }

        public int IndexOf(BaseListener value)
        {
            return InnerList.IndexOf(value);
        }

        [SuppressMessage("Microsoft.Globalization", "CA1303:DoNotPassLiteralsAsLocalizedParameters")]
        public void Insert(int index, BaseListener value)
        {
            if (value == null)
            {
                throw new ArgumentException("Listener cannot be null.");
            }

            value.SetOwner(_owner);
            InnerList.Insert(index, value);
        }

        [SuppressMessage("Microsoft.Globalization", "CA1303:DoNotPassLiteralsAsLocalizedParameters")]
        public void Remove(BaseListener value)
        {
            if (value == null)
            {
                throw new ArgumentException("Listener cannot be null.");
            }

            value.SetOwner(null);
            InnerList.Remove(value);
        }

        public void CopyTo(BaseListener[] array, int index)
        {
            ((ICollection)this).CopyTo(array, index);
        }

        public new IEnumerator<BaseListener> GetEnumerator()
        {
            foreach (BaseListener listener in InnerList)
            {
                yield return listener;
            }
        }
    }
}
